$(function () {
    function getUser() {
        $.get('/admin/user/detail', function (res) {
            const { email, nickname, password, userPic, username } = res.data
            $("[name=nickname]").val(nickname)
            $("[name=username]").val(username)
            $("[name=email]").val(email)
            $("[name=password]").val(password)
            $('.user_pic').prop('src', userPic)
        })
    }
    getUser()
    $('#exampleInputFile').change(function () {
        const fd = this.files[0]
        console.log(fd)
        const src = URL.createObjectURL(fd)
        $('.user_pic').prop('src', src)
    })
    $('.btn-edit').click(function () {
        const formdata = new FormData($('#form')[0])
        $.ajax({
            url: '/admin/user/edit',
            type: 'post',
            data: formdata,
            contentType: false,
            processData: false,
            success(res) {
                if (res.code === 200) {
                    location.href = 'main_count.html'
                }
            }
        })
    })
})